package org.Sort;

import org.Utils.ArrayIntegerComparator;

import java.util.Arrays;

public class testArraySort {
    public static void testDescendingOrder() {
        Integer[] ns = {28, 12, 89, 73, 65, 18, 96, 50, 8, 36};
        // 排序前:
        System.out.println(Arrays.toString(ns));

        Arrays.sort(ns, new ArrayIntegerComparator());

        // 排序后:
        System.out.println(Arrays.toString(ns));
        if (Arrays.toString(ns).equals("[96, 89, 73, 65, 50, 36, 28, 18, 12, 8]")) {
            System.out.println("测试成功");
        } else {
            System.out.println("测试失败");
        }
    }

    public static void testDeepToString() {
        int[][] ns = {
                {1, 2, 3},
                {2, 4, 5},
                {3, 6, 8}
        };
        System.out.println(Arrays.deepToString(ns));
    }

    public static void testArrayAverage() {
        // 用二维数组表示的学生成绩:
        int[][] scores = {
                { 82, 90, 91 },
                { 68, 72, 64 },
                { 95, 91, 89 },
                { 67, 52, 60 },
                { 79, 81, 85 },
        };

        // TODO:
        double average = 0;
        long sum = 0;
        long cnt = 0;
        for (int [] student : scores) {
            cnt += student.length;
            for (int score: student) {
                sum += score;
            }
        }
        average = (double) sum /cnt;
        System.out.println(average);

        if (Math.abs(average - 77.733333) < 0.000001) {
            System.out.println("测试成功");
        } else {
            System.out.println("测试失败");
        }
    }
}
